<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>建造者模式(生成器模式)-ES6</title>
</head>
<body>
    
</body>
<script>
    class AirplaneBuilder{
        constructor({color='black',weight='14000KG'}){
            this.color=color
            this.weight=weight
        }
        selectPower(type){
            const powerSystem={}
            switch(type){
                case 'small':
                    powerSystem.powerType='飞燕动力系统'
                    powerSystem.powerIntro='正在使用飞燕动力系统'
                    break
                case 'normal':
                    powerSystem.powerType = '雷鹰动力系统'
                    powerSystem.powerIntro = '正在使用雷鹰动力系统'
                    break
                case 'big':
                    powerSystem.powerType = '麦克斯动力系统'
                    powerSystem.powerIntro = '正在使用麦克斯动力系统'
                    break
            }
            this.powerSystem=powerSystem
        }
        selectTroops(type){
            const troops={}
            switch(type){
                case 'TPC':
                    troops.troopsType='远东总部'
                    troops.commander='居间惠'
                    break
                case 'STPC':
                    troops.troopsType='东南分部'
                    troops.commander='喜比'
                    break
                case 'KST':
                    troops.troopsType = '西北分部'
                    troops.commander = '辰东'
                    break
            }
            this.troops=troops
        }
    }
    class AirplaneMaker{
        constructor(params, power, troops) {
            const plane=new AirplaneBuilder(params)
            plane.selectPower(power)
            plane.selectTroops(troops)
            return plane
        }
        
    }

    let feiyan=new AirplaneMaker({color:'white',weight:'18520KG'},'big','TPC')
    console.log(feiyan)
</script>
</html>